<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>黔南民族师范学院综合教育学分认定系统</title>

    <link rel="stylesheet" href="/jquery-easyui-1.3.5/themes/icon.css" />
    <link rel="stylesheet" href="/jquery-easyui-1.3.5/themes/default/easyui.css"/>

    <script type="text/javascript" src="/jquery-easyui-1.3.5/jquery.min.js"></script>
    <script type="text/javascript" src="/jquery-easyui-1.3.5/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/jquery-easyui-1.3.5/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/jquery-easyui-1.3.5/datagrid-export.js"></script>
    <script type="text/javascript" th:inline="none">
        $(function(){
            $('#dg').datagrid({
                url:'/student/queryAllStudents',
                striped:true,
                idField:'id',
                fitColumn:true,
                nowrap:true,
                pagination:true,
                pageSize:10,
                pageList:[10,15,20,25],
                queryParams:{
                    keyword:'%%'
                },
                toolbar: [{
                    iconCls: 'icon-add',
                    text:'添加学生',
                    handler: function(){
                        parent.$("#win").window({
                            title:"添加学生",
                            width:500,
                            height:600,
                            content:'<iframe src="/student/save" frameborder="0" width="100%" height="100%">'
                        });
                    }
                },'-',{
                    iconCls: 'icon-edit',
                    text:'更新学生',
                    handler: function(){
                        var rows = $("#dg").datagrid("getSelections");
                        if(rows.length != 1){
                            $.messager.show({
                                title:'错误提示',
                                msg:'请选中一条记录',
                                timeout:5000,
                                showType:'slide'
                            });
                        }else{
                            parent.$("#win").window({
                                title:"更新学生",
                                width:500,
                                height:600,
                                content:'<iframe src="/student/update" frameborder="0" width="100%" height="100%">'
                            });
                        }
                    }
                },'-',{
                    iconCls: 'icon-remove',
                    text:'删除学生',
                    handler: function(){
                        var rows = $("#dg").datagrid("getSelections");
                        if(rows.length != 1){
                            $.messager.show({
                                title:'错误提示',
                                msg:'请选择一条记录',
                                timeout:5000,
                                showType:'slide'
                            });
                        }else{
                            $.messager.confirm('删除确认对话框', '是否要删除选中的记录?', function(r){
                                if (r){
                                    var ids = "";
                                    for(var i=0;i<rows.length;i++){
                                        ids+=rows[i].id + ",";
                                    }
                                    ids=ids.substring(0, ids.lastIndexOf(","));
                                    $.post("/student/studentDelete",{ids:ids},function(result){
                                        if(result=="ok"){
                                            $("#dg").datagrid("reload");
                                            $("#dg").datagrid("uncheckAll");
                                        }else{
                                            $.messager.show({
                                                title:'删除异常',
                                                msg:'无法删除,请检查操作!',
                                                timeout:2000,
                                                showType:'slide'
                                            });
                                        }
                                    });
                                }
                            });
                        }
                    }
                },'-',{
                    iconCls: 'icon-ok',
                    text:'导入学生',
                    handler: function() {
                        parent.$("#win").window({
                            title: "导入学生",
                            width:400,
                            height:200,
                            content: '<iframe src="/student/import" frameborder="0" width="100%" height="100%">'
                        });
                    }

                },'-',{
                    iconCls: 'icon-ok',
                    text:'导出学生Excel',
                    handler: function(){
                                $('#dg').datagrid('toExcel','DataGrid.xls');
                }
                    },'-',{
                    iconCls: 'icon-print',
                    text:'打印',
                    handler: function(){
                        $('#dg').datagrid('print','DataGrid')
                    }
                },'-',{
                    text:"&nbsp;&nbsp;&nbsp;&nbsp;<input type='text' id='ss' name='name' size='15'>"
                }
                ],

                columns:[[
                    {field:'check',checkbox:true},
                    {field:'id',title:'编号',width:50,align:'center'},
                    {field:'studentNumber',title:'学号',width:80,align:'center'},
                    {field:'studentName',title:'姓名',width:80,align:'center'},
                    {field:'gender',title:'性别(男/女)',width:80,align:'center',
                        formatter:function(value,row,index){
                            if(value){
                                return "<span>男</span>";
                            }else{
                                return "<span>女</span>";
                            }
                        }
                    },
                    {field:'identityCard',title:'身份证号',width:200,align:'center'},
                    {field:'enrollmentDate',title:'入学年份',width:80,align:'center'},
                    {field:'grade',title:'年级',width:40,align:'center'},
                    {field:'educationBackground',title:'学历',width:80,align:'center'},
                    {field:'year',title:'学制',width:40,align:'center'},
                    {field:'className',title:'所属班级',width:150,align:'center'},
                    {field:'majorName',title:'所属专业',width:150,align:'center'},
                    {field:'schoolName',title:'所属学院',width:150,align:'center'}
                ]]
            });
            $('#ss').searchbox({
                searcher:function(value,name){
                    $("#dg").datagrid('load',
                        {
                            keyword:'%'+value+'%'
                        });
                },
                prompt:'请输入学生姓名'
            });
        });

    </script>
</head>

<body>
<div>
    <!--判断是否显示，使用if, ${}可以使用工具类，可以看thymeleaf的中文文档-->
    <p style="color: red" th:value="${msg}" th:if="${not #strings.isEmpty(msg)}" >
    </p>

</div>
<table id="dg">
</table>
</body>
</html>
